<?php

namespace iBrand\Component\Goods\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class GoodsModel extends Model
{
	use SoftDeletes;

	protected $guarded = ['id'];

	public function __construct(array $attributes = [])
	{
		parent::__construct($attributes);

		$prefix = config('ibrand.app.database.prefix', 'ibrand_');

		$this->setTable($prefix . 'base_model');
	}

	public function setSpecIdsAttribute($value)
	{
		$this->attributes['spec_ids'] = implode(',', $value);
	}

	public function getSpecIdsAttribute($value)
	{
		return explode(',', $value);
	}

	public function hasManyAttribute()
	{
		return $this->belongsToMany(Attribute::class, config('ibrand.app.database.prefix', 'ibrand_') . 'base_model_attribute_relation', 'model_id', 'attribute_id');
	}
}